import { reqbannerlist } from "../../http/api"
//状态
let state = {
    // 1.初始化数据 
    arr: [],
}

//导出数据
let getters = {
    // 2.导出 
    arr(state) {
        return state.arr
    }
}

//修改状态
let mutations = {
    // 3.修改
    changeArr(state, arr) {
        state.arr = arr;
    }
}

//做异步 做逻辑
let actions = {
    // 4.请求arr 
    reqArr(context) {
       return new Promise((resolve,reject)=>{
         //发起请求
         reqbannerlist({ istree: true }).then(res => {
            if (res.data.code === 200) {
                //修改arr 
                let arr = res.data.list ? res.data.list : []
                context.commit("changeArr", arr)
                resolve()
            }
        })
       })
    }
}

// 导出
export default {
    state,
    getters,
    mutations,
    actions,
    namespaced: true
}